package ar.fi.uba.fallas2.business;

public class KindWeightPair {
	private AnswerKind kind;
	private int weight;
	public static final int UNKNOWN_WEIGHT 			= 0;
	public static final int INIT_YES_NO_WEIGHT 		= 14;
	public static final int INIT_PROBABLY_WEIGHT 	= 3;
	
	public KindWeightPair(AnswerKind kind, int weight) {
		this.setKind(kind);
		this.setWeight(weight);
	}
	
	public void updateWeight(AnswerKind newValue) {
		if (newValue.equals(AnswerKind.YES) || newValue.equals(AnswerKind.NO)) {
			if (this.getWeight() == UNKNOWN_WEIGHT) {
				this.setWeight(INIT_YES_NO_WEIGHT);
			} else if (this.getKind().equals(newValue)) {
				this.setWeight(this.getWeight()+1);
			} else {
				Double tmpWeight = this.getWeight() * 0.5;
				this.setWeight(tmpWeight <= 1 ? UNKNOWN_WEIGHT : tmpWeight.intValue());
			}
		} else if (newValue.equals(AnswerKind.PROBABLY) || newValue.equals(AnswerKind.DOUBTFUL)) {
			if (this.getWeight() == UNKNOWN_WEIGHT) {
				this.setWeight(INIT_PROBABLY_WEIGHT);
			} else if (this.getKind().equals(newValue)) {
				this.setWeight(this.getWeight()+1);
			} else {
				Double tmpWeight = this.getWeight() * 0.75;
				this.setWeight(tmpWeight <= 1 ? UNKNOWN_WEIGHT : tmpWeight.intValue());
			}
		} else {
			// Futuros tipos de respuestas
		}
	}

	public void setKind(AnswerKind kind) {
		this.kind = kind;
	}

	public AnswerKind getKind() {
		return kind;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int getWeight() {
		return weight;
	}
}
